const box = document.querySelector('.box')

function loadImgAsync(url) {
  const promise = new Promise(function (resolva, reject) {
    // 异步处理，消耗时间的代码
    const img = new Image()
    img.src = url
    img.onload = function(){
      resolva(img)
    }
    img.onerror = function(){
      reject(new Error(`load ${url} fail`))
    }
  })
  return promise;
}

const promise = loadImgAsync("https://b0.bdstatic.com/ugc/oICtGHb9ZDEZrlALZZlrhw20606cb17b203f6638763e428b45fb56.jpg@h_1280")
promise.then(function(data){
  box.appendChild(data)
},function(error){
  box.innerHTML = `图片加载失败，${error.message}`
})